package com.druid.controller;

import com.druid.model.PageBody;
import com.druid.model.ResponseData;
import com.druid.request.PageParam;
import com.druid.request.RolePermissionParam;
import com.druid.response.SecurityRolePermissionVm;
import com.druid.service.managementservice.ICeSecurityRolePermissionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author druid-elf
 * @since 2019-12-25
 */
@Api(tags={"后台管理角色权限表前端控制器"})
@RestController
@RequestMapping("/ceSecurityRolePermission")
@RequiredArgsConstructor
public class CeSecurityRolePermissionController {

    private final ICeSecurityRolePermissionService iCeSecurityRolePermissionService;

    @ApiOperation("得到后台管理角色权限表分页列表")
    @PostMapping(value = "getCeSecurityRolePermissionList")
    public ResponseData<PageBody<SecurityRolePermissionVm>> getCeSecurityRolePermissionList(@RequestBody @Validated PageParam pageParam ) {

        return ResponseData.SUCCESS(
                iCeSecurityRolePermissionService.getRolePermissionVmList( pageParam )
        );
    }

    @ApiOperation("得到角色权限列表并修改")
    @PostMapping(value = "updateBatchRolePermissionList")
    public ResponseData<String> updateBatchRolePermissionList(@RequestBody @Validated List<List<RolePermissionParam>> pageParamLists ) {


        return iCeSecurityRolePermissionService.updateBatchRolePermissionList( pageParamLists )
                ? ResponseData.SUCCESSWithResponse("修改成功")
                : ResponseData.FAILUREWithResponse("修改失败");
    }
}
